package com.webex.ta.hydra.gui.table.undo;

import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.gui.table.HydraTableModel;

import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-16
 * Time: 15:29:16
 */
public class InsertEdit extends AbstractUndoableEdit {
    private HydraTableModel model;
    private Command parent, child;
    private int pos;

    public InsertEdit(HydraTableModel model, Command parent, Command child, int pos) {
        this.model = model;
        this.parent = parent;
        this.child = child;
        this.pos = pos;
    }
    
    @Override
    public void undo() throws CannotUndoException {
        super.undo();
        parent.removeChild(child);
        model.fireTableDataChanged();
    }

    @Override
    public void redo() throws CannotRedoException {
        super.redo();
        parent.insertChild(pos, child);
        model.fireTableDataChanged();
    }
}
